﻿var curr_row = null;
//单选框脚本
function chooseRadio(objTr){
	if(curr_row != null && curr_row.tagName.toLowerCase() == "tr"){
	    curr_row.style.backgroundColor="#FFFFFF";
	    document.getElementById("radio_"+curr_row.id).checked = "false";
	}
	curr_row = objTr;
	curr_row.style.backgroundColor="#cceeee";
	document.getElementById("radio_"+curr_row.id).checked = "true";
}
//筛选框脚本
function chooseCheckbox(objTr,tabId){
	if(objTr.style.backgroundColor == "#cceeee"){
		objTr.style.backgroundColor = "#ffffff";
		document.getElementById("checkbox_"+objTr.id).checked = false;
		ChangeAllChecked(objTr,tabId);
	}else{
		objTr.style.backgroundColor = "#cceeee";
		document.getElementById("checkbox_"+objTr.id).checked = true;
		ChangeAllChecked(objTr,tabId);
	}
}
//日历（日期选择、不含时间）

function selectDate(contextPath,idName){
	var yyyy=new Array(2);
	//yyyy[1]="yyyy-MM-dd h:m";
	yyyy[1]="yyyy-MM-dd";
	var today = new Date();
	var theYear = today.getYear();
	var theMonth = today.getMonth() + 1;
	var theDay = today.getDate();
	var theHour = "00";//today.getHours();
	var theMinute = "00";//today.getMinutes();
	yyyy[0]=theYear+"-"+theMonth+"-"+theDay+"-"+theHour+"-"+theMinute;
	var dateString = showModalDialog(contextPath+"/component/calendar/calendar.htm",yyyy,"dialogWidth:309px;dialogHeight:380px;status:no;help:no;");
	if(dateString=="0")return;
	//treck.value = dateString;
	document.getElementById(idName).value = dateString;
}

function selectDateS(contextPath,idName){
	var yyyy=new Array(2);
	//yyyy[1]="yyyy-MM-dd h:m";
	yyyy[1]="yyyy-MM";
	var today = new Date();
	var theYear = today.getYear();
	var theMonth = today.getMonth() + 1;
	//var theDay = today.getDate();
	//var theHour = "00";//today.getHours();
	//var theMinute = "00";//today.getMinutes();
	yyyy[0]=theYear+"-"+theMonth;
	var dateString = showModalDialog(contextPath+"/component/calendar/calendar.htm",yyyy,"dialogWidth:309px;dialogHeight:380px;status:no;help:no;");
	if(dateString=="0")return;
	//treck.value = dateString;
	document.getElementById(idName).value = dateString;
}
//封装prototype nwe Ajax.Request提交
function ajaxRequest(url,pars,showReponse){
	var myAjax = new Ajax.Request(
	url,
	{
	method: "post",
	parameters: pars,
	onComplete: showResponse
	});
}


function ChangeAllChecked(objTr,tabId){
	var thick = document.getElementById("checkbox_"+objTr.id);
	var tabObj = eval(tabId);
	var cellIndex = thick.parentElement.cellIndex;
	var tHead= tabObj.getElementsByTagName("thead")[0];	
	var tBody = tabObj.getElementsByTagName("tbody")[0];
	if(thick.checked){
		var checkAllFlag = true;
		for(var i=0;i<tBody.rows.length;i++)
		{
			if(!tBody.rows[i].cells[cellIndex].childNodes[0].checked){
				checkAllFlag = false;
				break;
			}
		}
		if(checkAllFlag){
			tHead.rows[0].cells[cellIndex].childNodes[0].checked = thick.checked;
			tBody.checkAllFlag = thick.checked;
		}
	}else{
		tHead.rows[0].cells[cellIndex].childNodes[0].checked = thick.checked;
	}
}

function setObjStatus(objArray) {
	$("li" + objArray[0]).className="current";
	$("div" + objArray[0]).style.display="";
		for(i = 1;i < objArray.length;i++) {
		    	$("li" + objArray[i]).className = null;
		    	$("div" + objArray[i]).style.display="none";
		}
}
	//验证输入的只能为整数或者小数
function check_num_dot()
{
  if (window.event.keyCode > 57 || window.event.keyCode < 46)
	 {
  		 window.event.returnValue = false;   
	 }
   else
   {
      if(window.event.keyCode==47)
      {
   	    window.event.returnValue = false;
      }
      if(window.event.keyCode==46)
      {
         if (window.event.srcElement.value.indexOf(".")!=-1)
         {
        	window.event.returnValue = false;
         }
      }   
    }  
 }

//row上的checkBox的onclick事件;改变全选状态
function ChangeChecked(thick,tabId){
	var tabObj = eval(tabId);
	var cellIndex = thick.parentElement.cellIndex;
	var tHead= tabObj.getElementsByTagName("thead")[0];	
	var tBody = tabObj.getElementsByTagName("tbody")[0];
	if(thick.checked){
		var checkAllFlag = true;
		for(var i=0;i<tBody.rows.length;i++)
		{
			if(!tBody.rows[i].cells[cellIndex].childNodes[0].checked){
				checkAllFlag = false;
				break;
			}
		}
		if(checkAllFlag){
			tHead.rows[0].cells[cellIndex].childNodes[0].checked = thick.checked;
			tBody.checkAllFlag = thick.checked;
		}
	}else{
		tHead.rows[0].cells[cellIndex].childNodes[0].checked = thick.checked;
	}
}
function trselect(objTr,tabID){
	if(objTr.style.backgroundColor=="#ffffff" || objTr.style.backgroundColor==""){
		objTr.style.backgroundColor="#E5F0FD";
		document.getElementById("checkbox_"+objTr.id).checked = true;
	}else{
		objTr.style.backgroundColor="#ffffff";
		document.getElementById("checkbox_"+objTr.id).checked = false;
	}
}
//编码转换 传换后的格式像%E7%A7%98%E5%AF%86这种在后台用java.net.URLDecoder.decode(str, "UTF-8")转回来;
function encodeStr(str){
	if(str != ""){
		return encodeURI(encodeURI(str));
	}else{
		return "";
	}
}
//输入的必须为整数
function iswholeNumber(){
	if((event.keyCode<=47)||(event.keyCode>57)){
		event.returnValue=false;
	}
}



//删除方法
function del(url,pars){
	var myAjax = new Ajax.Request(
		url,
		{
			method: "post",
			parameters: pars,
			onComplete: showReponse
		});		
}

//消息提示
function pubMsg(url,pars){
	var myAjax = new Ajax.Request(
		url,
		{
			method: "post",
			parameters: pars,
			onComplete: showReponse
		});		
}

//格式化日期(2009-12-16 00:00:00 格式化后 2009-12-16)
function changeDate(Obj){
		var str =Obj;
		str = str.substr(0,str.lastIndexOf ("-")+3);
		return str;
	 } 
//初始化一个日期(2009-12-16)	
function getDate(){
	var now= new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var day=now.getDate();
	if(month<10){
		month = "0"+month;
	}
	if(day<10){
		day =  "0"+day;
	}
	    return year+"-"+month+"-"+day;
}

//两个日期进行比较
function checkdate(sdate,edate){   
 //得到日期值并转化成日期格式，replace(/\-/g, "\/")是根据验证表达式把日期转化成长日期格式，这样
 //再进行判断就好判断了
    var sDate = new Date(sdate.replace(/\-/g, "\/"));
    var eDate = new Date(edate.replace(/\-/g, "\/"));
    if(sDate > eDate){
   	 	return true;
  	 }else{
  		return false;
  	}
 }


 function fomatMoneys(money,name){   
   if(/[^0-9\.]/.test(money)) return money;   
   money=money.replace(/^(\d*)$/,"$1.");   
   money=(money+"00").replace(/(\d*\.\d\d)\d*/,"$1");   
   money=money.replace(".",",");   
   var re=/(\d)(\d{3},)/;   
   while(re.test(money)){   
     money=money.replace(re,"$1,$2");   
   }   
   money = money.replace(/,(\d\d)$/,".$1"); 
   $(name).value = money;
     //return "￥" + money.replace(/^\./,"0.")   
}
 
 
function fomatMoneyeval(money){   
        if(/[^0-9\.]/.test(money)) return money;   
        money=money.replace(/^(\d*)$/,"$1.");   
        money=(money+"00").replace(/(\d*\.\d\d)\d*/,"$1");   
        money=money.replace(".",",");   
        var re=/(\d)(\d{3},)/;   
        while(re.test(money)){   
          money=money.replace(re,"$1,$2");   
        }   
        money=money.replace(/,(\d\d)$/,".$1");   
        return money;   
        } 

//校验定位
 function isSelectFocus(obj){
	try{
		$(obj).select();
		$(obj).focus();
        }catch(e){
		$(obj).focus();
	}
}

//清除带有选择按钮的文本框的值以及清除该文本的隐藏Id值
//@param objId  文本隐藏ID(属性)名称
//@param objName  文本的(属性)昵称
 function clearText(objId,objName){
		$(objId).value = "";
		$(objName).value = "";
 }